package com.gdufe.seckill.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.gdufe.seckill.entity.SessionEntity;
import com.gdufe.seckill.service.SessionAdminService;
import com.gdufe.common.utils.PageUtils;
import com.gdufe.common.utils.R;


@RestController
@RequestMapping("seckill/session/admin")
public class SessionAdminController {
    @Autowired
    private SessionAdminService sessionAdminService;

    /**
     *获取所有场次信息
     */
    @RequestMapping("/getSessions")
    public R getSessions(){
        List<SessionEntity> sessions = sessionAdminService.getSessions();
        return R.ok().put("sessions",sessions);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sessionAdminService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		SessionEntity session = sessionAdminService.getById(id);

        return R.ok().put("session", session);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SessionEntity session){
		sessionAdminService.save(session);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SessionEntity session){
		sessionAdminService.updateById(session);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		sessionAdminService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
